import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import set from '@dfeidao/atom-web/local/set';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import render from '@dfeidao/atom-web/render/render';
import set_node_cls from '@dfeidao/atom-web/ui/set-node-cls';
import show from '@dfeidao/atom-web/ui/show';
import p001 from './p001';
import p002 from './p002';
import p003 from './p003';

export default async function a001(fd: IFeidaoAiBrowserComponent) {
	// todo
	// 设置样式
	const add = fd.data.node.querySelector<HTMLDivElement>('[data-id="add"]');
	set_node_cls(add, 'display-n', false);
	const jieshouren = fd.data.node.querySelectorAll<HTMLDivElement>('[data-id="getUser"]');
	for (let i = 0; i < jieshouren.length; i++) {
		set_node_cls(jieshouren[i], 'display-n', true);
		jieshouren[i].removeAttribute('data-id');
	}
	// a04需要判断是否重复data-id="getUser"
	const arr = Array();
	set(fd, 'arr1', arr);
	// 查询和渲染
	const res = await nodejs<{ dt: Array<{}>, c: number }>('notification-notice/zj-000006/s001',
		{
			filter: {
				pn: 1
			}
		});
	const dtData = fd.data.node.querySelector<HTMLDivElement>('[data-feidao-presentation="p001"]');
	const dtNoData = fd.data.node.querySelector<HTMLDivElement>('[data-feidao-presentation="p002"]');
	const dtPn = fd.data.node.querySelector<HTMLDivElement>('[data-feidao-presentation="p003"]');
	if (res.dt.length) {
		render(fd, res.dt, p001, 'p001', 'inner');
		render(fd, res.c, p003, 'p003', 'inner');
		dtNoData.style.display = 'none';
		dtData.style.display = 'block';
		dtPn.style.display = 'block';
	} else {
		render(fd, '', p002, 'p002', 'inner');
		dtNoData.style.display = 'block';
		dtData.style.display = 'none';
		dtPn.style.display = 'none';
	}
	show(fd.data.node);
}
